"use strict";
const common_vendor = require("../../common/vendor.js");
const common_api = require("../../common/api.js");
require("../../common/request.js");
const _sfc_main = {
  data() {
    return {
      user: {
        info: {
          userName: "",
          realName: "",
          age: 0,
          gender: 0,
          phone: "",
          emergencyName: "",
          emergencyPhone: ""
        }
      },
      genderArr: ["女", "男"],
      __userInfo: {}
    };
  },
  computed: {
    noChange() {
      if (this.__userInfo == JSON.stringify(this.user.info)) {
        return true;
      } else {
        return false;
      }
    }
  },
  onLoad(e) {
    this.user = JSON.parse(e.user);
    this.__userInfo = JSON.stringify(this.user.info);
  },
  methods: {
    bindGenderChange(e) {
      this.user.info.gender = e.detail.value;
    },
    putProfile(res) {
      if (res.confirm) {
        common_vendor.index.showLoading({ title: "正在上传中" });
        common_api.putVisitorProfile_id(this.user.id, this.user.info).then((res2) => {
          common_vendor.index.hideLoading();
          this.setPageValue();
          common_vendor.index.showToast({
            icon: "none",
            title: "上传成功"
          });
        }).catch((err) => {
          common_vendor.index.hideLoading();
        });
      } else if (res.cancel) {
        console.log("用户点击取消");
      }
    },
    updateProfile() {
      if (this.confirmUserInfo(this.user.info)) {
        common_vendor.index.showModal({
          content: "请确认是否提交该个人信息更新",
          success: (res) => {
            this.putProfile(res);
          }
        });
      }
    },
    confirmUserInfo(userInfo) {
      console.log(userInfo);
      if (userInfo.userName.length > 16 || userInfo.userName.length < 2) {
        common_vendor.index.showToast({ icon: "none", title: "错误！昵称应为2-16位中文或英文" });
        return false;
      } else if (userInfo.realName.length > 16 || userInfo.realName.length < 2) {
        common_vendor.index.showToast({ icon: "none", title: "错误！姓名应为2-16位中文或英文" });
        return false;
      } else if (userInfo.emergencyName.length > 16 || userInfo.emergencyName.length < 2) {
        common_vendor.index.showToast({ icon: "none", title: "错误！紧急联系人姓名应为2-16位中文或英文" });
        return false;
      } else if (!/^1[3-9]\d{9}$/.test(userInfo.phone)) {
        common_vendor.index.showToast({ icon: "none", title: "错误！您的电话不符国内手机号格式" });
        return false;
      } else if (!/^1[3-9]\d{9}$/.test(userInfo.emergencyPhone)) {
        common_vendor.index.showToast({ icon: "none", title: "错误！紧急联系人电话不符国内手机号格式" });
        return false;
      }
      return true;
    },
    setPageValue() {
      let pages = getCurrentPages();
      let prevPage = pages[0];
      prevPage.$vm.user = this.user;
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: $data.user.info.userName,
    b: common_vendor.o(($event) => $data.user.info.userName = $event.detail.value),
    c: $data.user.info.realName,
    d: common_vendor.o(($event) => $data.user.info.realName = $event.detail.value),
    e: $data.user.info.age,
    f: common_vendor.o(($event) => $data.user.info.age = $event.detail.value),
    g: common_vendor.t($data.genderArr[$data.user.info.gender]),
    h: $data.user.info.gender,
    i: $data.genderArr,
    j: common_vendor.o((...args) => $options.bindGenderChange && $options.bindGenderChange(...args)),
    k: $data.user.info.phone,
    l: $data.user.info.emergencyName,
    m: common_vendor.o(($event) => $data.user.info.emergencyName = $event.detail.value),
    n: $data.user.info.emergencyPhone,
    o: common_vendor.o(($event) => $data.user.info.emergencyPhone = $event.detail.value),
    p: common_vendor.o((...args) => $options.updateProfile && $options.updateProfile(...args)),
    q: $options.noChange
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "D:/Project/heart-3.0/heart-field-3.0/pages/profile/profile.vue"]]);
wx.createPage(MiniProgramPage);
